package com.example.zhuma;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.zhuma.adapter.ImagePagerAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    //定义listView当中要使用的图标信息列表
    private static final int[] iconArray={R.drawable.axmf,R.drawable.mofei,R.drawable.poc,R.drawable.pgml};
    //定义ListView要显示的文本标题列表
    private static final String[] titleArray={"阿西莫夫效应","墨菲定律","破窗效应","皮格马利翁效应"};
    //定义ListView要显示的文本详情信息
    private static final String[] contentArray={"想象未来最大的困难是缺了对关键技术的想象,细节越多,错误也就越多。","如果有两种或两种以上的方式去做某件事情，而其中一种选择方式将导致灾难，则必定有人会做出这种选择。","环境中的不良现象如果被放任存在，会诱使人们仿效，甚至变本加厉。","皮格马利翁效应表明，当一个人受到他人的信任、赞美或期望时，会更加努力地追求自己的目标并取得成功。"};

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //去除上方导航框
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
        //设置轮播图以及其显示内容
        ViewPager vp_content = findViewById(R.id.viewPager);
        ImagePagerAdapter adapter = new ImagePagerAdapter(this);
        vp_content.setAdapter(adapter);
        //设置显示心理知识信息的文本内容ListView
        ListView main_lv = findViewById(R.id.main_lv);
        //声明一个映射对象的列表，用于表示心理知识的icon、title和content
        List<Map<String,Object>> list = new ArrayList<>();
        for (int i = 0; i < iconArray.length; i++) {
            Map<String,Object> item = new HashMap<>();
            item.put("icon",iconArray[i]);
            item.put("title",titleArray[i]);
            item.put("content",contentArray[i]);
            list.add(item);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.activity_main_item
                ,new String[]{"icon","title","content"}
                ,new int[]{R.id.main_item_iv,R.id.main_item_tv1,R.id.main_item_tv2});
        main_lv.setAdapter(simpleAdapter);
        //给四个链接图标添加点击事件
        ImageView imageView1 = findViewById(R.id.yuyin_icon_iv);
        ImageView imageView2 = findViewById(R.id.locate_icon_iv);
        ImageView imageView3 = findViewById(R.id.monitor_icon_iv);
        ImageView imageView4 = findViewById(R.id.analyse_icon_iv);
        imageView1.setOnClickListener(this);
        imageView2.setOnClickListener(this);
        imageView3.setOnClickListener(this);
        imageView4.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
        if (view.getId()==R.id.yuyin_icon_iv)
        {
            intent.setClass(this,VoiceActivity.class);
            startActivity(intent);
        }
        if (view.getId()==R.id.locate_icon_iv)
        {
            intent.setClass(this,LocateActivity.class);
            startActivity(intent);
        }
        if (view.getId()==R.id.monitor_icon_iv)
        {
            intent.setClass(this,MonitorActivity.class);
            startActivity(intent);
        }
        if (view.getId()==R.id.analyse_icon_iv)
        {
            intent.setClass(this,AnalyseActivity.class);
            startActivity(intent);
        }

    }
}